package com.lemon.smartsafetynew.ui.activity.monitor;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.common.CommonBo;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.monitor.MonitorMenu;
import com.lemon.smartsafetynew.ui.activity.air.AirCompanyListActivity;
import com.lemon.smartsafetynew.ui.activity.air.AirListActivity;
import com.lemon.smartsafetynew.ui.activity.electrical.ElectricalSafeHomeActivity;
import com.lemon.smartsafetynew.ui.activity.electrical.ElectricalSafePointListActivity;
import com.lemon.smartsafetynew.ui.activity.highDanger.HighDangerCompanyListActivity;
import com.lemon.smartsafetynew.ui.activity.highDanger.HighDangerListActivity;
import com.lemon.smartsafetynew.ui.activity.tank.TankCompanyListActivity;
import com.lemon.smartsafetynew.ui.activity.tank.TankListActivity;
import com.lemon.smartsafetynew.ui.adapter.monitor.MonitorMenuAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;
import com.lemon.smartsafetynew.util.user.UserTypeUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 实时监测
 * Created by Andrew on 2017/8/7.
 */
public class MonitorHomeActivity extends SwipeBackActivity
        implements RecyclerTClickListener<MonitorMenu> {

    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;

    private MonitorMenuAdapter mAdapter;
    private List<MonitorMenu> mDataList = new ArrayList<>();

    private static final int[] imageId = new int[]{
            R.mipmap.icon_real_tank,
            R.mipmap.icon_real_air,
            R.mipmap.icon_real_danger,
            R.mipmap.icon_real_electrical,
            R.mipmap.icon_real_video,
    };

    private static final int[] name = new int[] {
            R.string.real_monitor_tank_str,
            R.string.real_monitor_air_str,
            R.string.real_monitor_high_danger_str,
            R.string.real_monitor_electrical_str,
            R.string.real_monitor_video_str
    };

    @Override
    protected void initTitle() {
        this.setBarTitle(getString(R.string.work_options_main_4));
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(MonitorHomeActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_monitor_home;
    }

    @Override
    protected void initViews() {
        super.initViews();

        if (CommonBo.Project.CAMPUS.getValue().equals(Constants.VERSION_SUFFIX)) {

            //校园智慧安全服务云
            MonitorMenu monitorElectrical = new MonitorMenu(imageId[3], getString(name[3]));
            MonitorMenu monitorVideo = new MonitorMenu(imageId[4], getString(name[4]));
            mDataList.add(monitorElectrical);
            mDataList.add(monitorVideo);

        } else {

            for (int i = 0; i < imageId.length; i++) {
                MonitorMenu monitorMenu = new MonitorMenu(imageId[i], getString(name[i]));
                mDataList.add(monitorMenu);
            }

        }

        GridLayoutManager gridLayoutManager = new GridLayoutManager(MonitorHomeActivity.this, 3);
        mAdapter = new MonitorMenuAdapter(mDataList, MonitorHomeActivity.this);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.setAdapter(mAdapter);
    }

    @Override
    public void onItemClick(MonitorMenu data, int position) {
        switch (data.getImageId()) {
            case R.mipmap.icon_real_tank:
                //储罐实时监控
                if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
                    UIHelper.showActivity(MonitorHomeActivity.this, TankListActivity.class);
                } else {
                    UIHelper.showActivity(MonitorHomeActivity.this, TankCompanyListActivity.class);
                }
                break;
            case R.mipmap.icon_real_air:
                //可燃/有毒气体
                if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
                    UIHelper.showActivity(MonitorHomeActivity.this, AirListActivity.class);
                } else {
                    UIHelper.showActivity(MonitorHomeActivity.this, AirCompanyListActivity.class);
                }
                break;
            case R.mipmap.icon_real_danger:
                //高危工艺
                if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
                    UIHelper.showActivity(MonitorHomeActivity.this, HighDangerListActivity.class);
                } else {
                    UIHelper.showActivity(MonitorHomeActivity.this, HighDangerCompanyListActivity.class);
                }
                break;
            case R.mipmap.icon_real_electrical:
                //电气火灾监测
                if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
                    Bundle bundle = new Bundle();
                    ElectricalCompanyVo vo =new ElectricalCompanyVo();
                    vo.setBoxId("");
                    vo.setCompanyName(AccountUtil.getCompanyName());
                    bundle.putSerializable(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO, vo);
                    UIHelper.showActivity(MonitorHomeActivity.this, bundle,ElectricalSafePointListActivity.class);
                } else {
                    UIHelper.showActivity(MonitorHomeActivity.this, ElectricalSafeHomeActivity.class);
                }
                break;
            case R.mipmap.icon_real_video:
                //视频监控
                if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
                    UIHelper.showActivity(MonitorHomeActivity.this, MonitorVideoActivity.class);
                } else {
                    UIHelper.showActivity(MonitorHomeActivity.this, MonitorVideoHomeActivity.class);
                }
                break;
        }
    }
}
